package com.example.android.ui.searchHB;

import com.example.android.bean.SearchHB;

import java.util.List;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class SearchHBPersenter implements SearchHBContract.ISearchHBPresenter{
    SearchHBContract.ISearchHBModel searchHBModel;
    private SearchHBContract.ISearchHBView searchHBView;
    public SearchHBPersenter(SearchHBContract.ISearchHBView searchHBView){
        this.searchHBView= searchHBView;
        searchHBModel = new SearchHBModel();
    }
    @Override
    public void getHBBasisList(String type, String value, int low, int high) {
        searchHBModel.getHBBasisList(type,value,low,high)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<List<SearchHB>>() {
                    @Override
                    public void accept(List<SearchHB> searchHBList) throws Throwable {
                        searchHBView.getHBBasisListSuccess(searchHBList);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                        searchHBView.getHBBasisListError(throwable);
                    }
                });
    }
}
